  <template>
  <div>
    <van-search
      @focus="tiaozhuan"
      v-model="value"
      placeholder="商品搜索,共239款好物"
    />
    <ul class="nav">
      <li
        v-for="(item, index) in topList"
        :key="item.id"
        :class="index == current ? 'red' : ''"
        @click="events(item.id, index)"
      >
        {{ item.name }}
      </li>
    </ul>
    <!-- <div class="banner" v-for="item in list" :key="item.id">
      <img :src="item.banner_url" alt="" />
    </div> -->

    <ul class="list">
      <router-link
        tag="li"
        v-for="item in list"
        :key="item.id"
        router-link
        :to="`/category/list?id=${item.id}`"
      >
        <img :src="item.wap_banner_url" alt="" width="72px" height="72px" />
        <p>{{ item.name }}</p>
      </router-link>
    </ul>
  </div>
</template>

   <script>
import { indexaction, currentaction } from "@/api/category/";
export default {
  data() {
    return {
      value: "",
      topList: [],
      current: 0,
      list: [],
    };
  },
  computed: {},
  created() {
    // indexaction().then((res) => {
    //   console.log(res);
    //   this.topList = res.data.categoryList;
    // });
    this.init();
  },
  mounted() {},

  methods: {
    tiaozhuan() {
      this.$router.push({ path: "home/search" });
    },
    async init() {
      var res = await indexaction();
      this.topList = res.data.categoryList;
      var res1 = await currentaction({
        id: res.data.categoryList[0].id,
      });
      console.log(res1);
      this.list = res1.data.data.currentOne.subList;
    },
    async events(val, index) {
      this.current = index;
      var res1 = await currentaction({
        id: val,
      });
      this.list = res1.data.data.currentOne.subList;
    },
  },
};
</script>
<style scoped lang='scss'>
.red {
  color: red;
  font-size: 14px;
}
.nav {
  float: left;
  display: flex;
  flex-wrap: wrap;
  font-size: 12px;
  text-align: center;
  width: 2.16rem;
  height: 100%;
  // height: 570px;
  text-align: center;
  // border: 1px solid green;

  li {
    width: 84px;
    height: 45px;
    line-height: 45px;
  }
}

.list {
  float: right;
  margin-left: 0;
  width: 260px;
  // width: 250px;

  li {
    float: left;
    margin-right: 6px;
    margin-bottom: 6px;
    width: 80px;
    width: 74px;
    height: 88px;
    // border: 1px solid red;

    p {
      margin: 0;
    }
  }
}
</style>